package cn.enilu.flash.warpper;

import cn.enilu.flash.conf.properties.LocalFileProperties;
import cn.enilu.flash.enums.body.*;
import cn.enilu.flash.service.system.impl.ConstantFactory;
import cn.enilu.flash.utils.DateTime;
import cn.enilu.flash.utils.DateUtil;
import cn.enilu.flash.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @Description
 * @Author Spark
 * @Date Created in (2019/10/31 15:39)
 * @Version v1.0
 * @Modify
 **/
public class CustInfoWarpper extends BaseControllerWarpper  {

    private LocalFileProperties localFileProperties;

    public CustInfoWarpper(List<Map<String, Object>> list, LocalFileProperties localFileProperties) {
        super(list);
        this.localFileProperties = localFileProperties;
    }

    public CustInfoWarpper(Map<String, Object> map, LocalFileProperties localFileProperties) {
        super(map);
        this.localFileProperties = localFileProperties;
    }

    @Override
    public void warpTheMap(Map<String, Object> map) {
        map.put("cardTypeName", CardType.valueOfCode((Integer) map.get("cardType")));
        map.put("genderName", Gender.valueOfCode((Integer) map.get("gender")));
        map.put("ownerFlagName", OwnerFlag.valueOfCode((Integer) map.get("ownerFlag")));
        map.put("stateName", State.valueOfCode((Integer) map.get("state")));
        if(map.get("cardFrontFileId") != null && (Long)map.get("cardFrontFileId") > 0) {
            map.put("cardFrontFileUrl", localFileProperties.getUrl() + ConstantFactory.me().getFilePathById((Long) map.get("cardFrontFileId")));
        }
        if(map.get("cardBackFileId") != null && (Long)map.get("cardBackFileId") > 0) {
            map.put("cardBackFileUrl", localFileProperties.getUrl() + ConstantFactory.me().getFilePathById((Long) map.get("cardBackFileId")));
        }
        if(map.get("contractFileId") != null && (Long)map.get("contractFileId") > 0) {
            map.put("contractFileUrl", localFileProperties.getUrl() + ConstantFactory.me().getFilePathById((Long) map.get("contractFileId")));
        }
        if(map.get("inDate") != null ) {
            map.put("inDateStr", DateUtil.getDay((Date)map.get("inDate")));
        }
        if(map.get("outDate") != null ) {
            map.put("outDateStr", DateUtil.getDay((Date)map.get("outDate")));
        }
    }
}
